﻿#region using statements

using System;

using Microsoft.Xna.Framework;

using NGen.Managers.GUI;

using Nuclex.UserInterface;
using Nuclex.UserInterface.Controls;
using Nuclex.UserInterface.Controls.Desktop;

#endregion

namespace XNAGameDemo.GUI
{
	public delegate void ButtonClick();

	public class GUIElementPlay2State : GUIElement
	{
		private readonly ButtonControl m_clearButton = new ButtonControl();

		private readonly ButtonControl m_goButton = new ButtonControl();

		private readonly LabelControl m_label = new LabelControl();

		private readonly ButtonControl m_randomizeButton = new ButtonControl();

		private readonly ButtonControl m_toggleDebugDisplayButton = new ButtonControl();

		private readonly WindowWithOkButtonControl m_window = new WindowWithOkButtonControl();

		public event ButtonClick OnGoButtonClick;

		public event ButtonClick OnClearButtonClick;

		public event ButtonClick OnRandomizeButtonClick;

		public event ButtonClick OnToggleDebugDisplayButtonClicked;

		protected override void _Initialize() {
			m_window.Bounds = new UniRectangle(new UniScalar(0.5f, -250.0f), new UniScalar(0.25f, 0.0f), 500, 500);
			m_window.OkButton.Pressed += _OkButtonPressed;
			_Children.Add(m_window);

			m_label.Bounds = new UniRectangle(new UniScalar(0.075f, 0.0f), new UniScalar(0.2f, 0.0f), 0, 0);
			m_label.Text = "This state demonstrates how to use the " + "pathfinding manager.\n\nRed tiles reprensent tiles which " + "were searched,\n    but are not on the optimal path.\nBlue " + "tiles were seen, but not searched.\nYellow tiles are " + "the optimal path.\nNo tiles shown means no path could be " + "found.\n    (start or end point is blocked off) \n\n" + "Controls:\n\nLeft click - place " + "start point\nRight click - place end point\nMiddle click: " + "add/remove wall\nSpacebar - find a path (go button)\n" + "Delete - clears previous path data (clear button)\n" + "Enter - randomize the wall placement (randomize button)";
			m_window.Children.Add(m_label);

			m_goButton.Bounds = new UniRectangle(new UniScalar(0.01f, 160.0f), new UniScalar(0.01f, 0.0f), new UniScalar(150), new UniScalar(30));
			m_goButton.Text = "Go";

			m_randomizeButton.Bounds = new UniRectangle(new UniScalar(0.01f, 320.0f), new UniScalar(0.01f, 0.0f), new UniScalar(150), new UniScalar(30));
			m_randomizeButton.Text = "Randomize";

			m_clearButton.Bounds = new UniRectangle(new UniScalar(0.01f, 480.0f), new UniScalar(0.01f, 0.0f), new UniScalar(150), new UniScalar(30));
			m_clearButton.Text = "Clear";

			m_toggleDebugDisplayButton.Bounds = new UniRectangle(new UniScalar(0.01f, 640.0f), new UniScalar(0.01f, 0.0f), new UniScalar(150), new UniScalar(30));
			m_toggleDebugDisplayButton.Text = "Toggle Debug";

			_Children.Add(m_goButton);
			_Children.Add(m_randomizeButton);
			_Children.Add(m_clearButton);
			_Children.Add(m_toggleDebugDisplayButton);
		}

		protected override void Update(GameTime p_gameTime) {}

		protected override void _Cleanup() {}

		private void _OkButtonPressed(object p_sender, EventArgs p_e) {
			_Children.Remove(m_window);
			m_goButton.Pressed += _GoButtonPressed;
			m_randomizeButton.Pressed += _RandomizeButtonPressed;
			m_clearButton.Pressed += _ClearButtonPressed;
			m_toggleDebugDisplayButton.Pressed += _ToggleDebugDisplayButtonPressed;
		}

		private void _GoButtonPressed(object p_sender, EventArgs p_e) {
			if(OnGoButtonClick != null) {
				OnGoButtonClick();
			}
		}

		private void _RandomizeButtonPressed(object p_sender, EventArgs p_e) {
			if(OnRandomizeButtonClick != null) {
				OnRandomizeButtonClick();
			}
		}

		private void _ClearButtonPressed(object p_sender, EventArgs p_e) {
			if(OnClearButtonClick != null) {
				OnClearButtonClick();
			}
		}

		private void _ToggleDebugDisplayButtonPressed(object p_sender, EventArgs p_e) {
			if(OnToggleDebugDisplayButtonClicked != null) {
				OnToggleDebugDisplayButtonClicked();
			}
		}
	}
}